package com.dzl.order.service.impl;

import com.dzl.base.service.BaseServiceImpl;
import com.dzl.order.dao.WelfareOrderGoodsMapper;
import com.dzl.order.pojo.WelfareOrderGoods;
import com.dzl.order.pojo.vo.*;
import com.dzl.order.service.WelfareOrderGoodsService;
import com.dzl.util.EmptyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * 订单商品表(WelfareOrderGoods)表服务实现类
 * @author ChenLong
 * @date 2021-05-21 14:21:41
 */
@Service
public class WelfareOrderGoodsServiceImpl extends BaseServiceImpl<WelfareOrderGoods> implements WelfareOrderGoodsService {

    @Autowired
    private WelfareOrderGoodsMapper mapper;

    @Override
    public List<OrderPayCardVo> selectOrderPayCarVo(Integer orderId) {
        return mapper.selectOrderPayCarVo(orderId);
    }

    @Override
    public List<WelfareOrderGoodsCardVo> getOrderGoodsByOrderId(Integer orderId) {
        return mapper.getOrderGoodsByOrderId(orderId);
    }

    @Override
    public WelfareOrderGoodsProductVo getOrderGoodsProductInfoByOrderId(Integer orderId) {
        return mapper.getOrderGoodsProductInfoByOrderId(orderId);
    }

    @Override
    public WelfareOrderGoodsPayDetailVo getPaymentInfo(Integer orderId, Integer type) {
        WelfareOrderGoodsPayDetailVo welfareOrderGoodsPayDetailVo = new WelfareOrderGoodsPayDetailVo();
        BigDecimal totalCashAmount;
        List<WelfareOrderGoodsPayInfoVo> orderGoodsPayInfoVoList;
        // 查询原订单支付信息
        if (type.equals(1)) {
            orderGoodsPayInfoVoList = mapper.getPaymentCreditsInfo(orderId);
            totalCashAmount = mapper.getPaymentCashInfo(orderId);
        } else {
            // 查询新订单支付信息（拆单以后）
            orderGoodsPayInfoVoList = mapper.getPaymentCreditsInfoForSplit(orderId);
            totalCashAmount = mapper.getPaymentCashInfoForSplit(orderId);
        }
        if (EmptyUtils.isNotEmpty(totalCashAmount)) {
            welfareOrderGoodsPayDetailVo.setTotalCashAmount(totalCashAmount);
        }
        if (EmptyUtils.isNotEmpty(orderGoodsPayInfoVoList)) {
            welfareOrderGoodsPayDetailVo.setOrderGoodsPayInfoVoList(orderGoodsPayInfoVoList);
        }
        return welfareOrderGoodsPayDetailVo;
    }


    @Override
    public List<WelfareOrderGoods> getPaidOrderGoodsBySecretCardId(Integer cardSecretId, Integer goodsId) {
        return mapper.getPaidOrderGoodsBySecretCardId(cardSecretId,goodsId);
    }

    @Override
    public List<WelfareOrderGoodsVo> selectOrderGoodsVoByOrderId(Integer orderId) {
        return mapper.selectOrderGoodsVoByOrderId(orderId);
    }


    @Override
    public List<WelfareOrderGoods> selectOrderGoodsByOrderIds(String orderIds) {
        return mapper.selectOrderGoodsByOrderIds(orderIds);
    }
}
